﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Complex;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
   


            string json = File.ReadAllText("data.json");
            var data1= Newtonsoft.Json.JsonConvert.DeserializeObject<List<SalePlan>>(json);

            var data2 = Multi(data1, 0, new int?[] { 10, 5 });
            //var data3= Multi(data1, 0,new int?[] {10,5 });

            var data3= Newtonsoft.Json.JsonConvert.SerializeObject(data2);

            File.WriteAllText("data2.json",data3);


        }
        //0=10+5
        static List<SalePlan> Multi(List<SalePlan> list,int parampterid, int?[] multiline) {
           var computeLine=  list.FirstOrDefault(a => a.parampter_id == parampterid);
            if (computeLine == null)
            {
                computeLine = new SalePlan();
                computeLine.parampter_id = parampterid;
            }
            else {
                list.Remove(computeLine);
            }
            computeLine.M1 = list.Where(a => multiline.Contains(a.parampter_id)).Sum(a => a.M1);
            computeLine.M2 =  list.Where(a => multiline.Contains(a.parampter_id)).Sum(a => a.M2);
            computeLine.M3 =  list.Where(a => multiline.Contains(a.parampter_id)).Sum(a => a.M3);
            computeLine.M4 =  list.Where(a => multiline.Contains(a.parampter_id)).Sum(a => a.M4);
            computeLine.M5 =  list.Where(a => multiline.Contains(a.parampter_id)).Sum(a => a.M5);
            computeLine.M6 =  list.Where(a => multiline.Contains(a.parampter_id)).Sum(a => a.M6);
            computeLine.M7 =  list.Where(a => multiline.Contains(a.parampter_id)).Sum(a => a.M7);
            computeLine.M8 =  list.Where(a => multiline.Contains(a.parampter_id)).Sum(a => a.M8);
            computeLine.M9 =  list.Where(a => multiline.Contains(a.parampter_id)).Sum(a => a.M9);
            computeLine.M10 = list.Where(a => multiline.Contains(a.parampter_id)).Sum(a => a.M10);
            computeLine.M11 = list.Where(a => multiline.Contains(a.parampter_id)).Sum(a => a.M11);
            computeLine.M12 = list.Where(a => multiline.Contains(a.parampter_id)).Sum(a => a.M12);
            list.Add(computeLine);
            return list;

        }

        

    }
}
